<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>集合实践</title>
</head>
<body>
    <script>
        //1. 数组去重  
        // let arr = ['大事儿','小事儿','好事儿','坏事儿','小事儿'];
        // let result = [...new Set(arr)];
        // console.log(result);

        //2. 交集
        let arr = [1,2,3,4,3,2,1];
        let arr2 = [3,4,5,6,5,4,3]; // indexOf  include

        // let inter = [...new Set(arr)].filter(item => {
        //     //判断 item 是否存在于 arr2
        //     let s = new Set(arr2);
        //     //
        //     return s.has(item);
        // });

        //3. 并集
        // let union = [...new Set([...new Set(arr), ...new Set(arr2)])];
        // console.log(union);

        //4. 差集
        // let diff = [...new Set(arr)].filter(item => {
        //     let s = new Set(arr2);
        //     return !s.has(item);
        // });
        // console.log(diff);

    </script>
</body>
</html>